{% extends "base.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}
{% load ietf_filters person_filters textfilters %}
{% block title %}
    Liaison statement:
    {% include 'liaisons/liaison_title.html' %}
{% endblock %}
{% block content %}
    {% origin %}
    <h1>
        Liaison statement
        <br>
        <small class="text-body-secondary">{% include 'liaisons/liaison_title.html' %}</small>
    </h1>
    {% include "liaisons/liaison_desc.html" only %}
    {% include "liaisons/detail_tabs.html" %}
    <table class="table table-sm table-striped">
        <tbody>
        <tr>
            <th scope="row">State</th>
            <td>{{ liaison.state }}</td>
        </tr>
        <tr>
            <th scope="row">Submitted Date</th>
            <td>{{ liaison.submitted|date:"Y-m-d" }}</td>
        </tr>
        <tr>
            <th scope="row">From Group{{ liaison.from_groups.all|pluralize }}</th>
            <td>{{ liaison.from_groups_display }}</td>
        </tr>
        {% if liaison.from_contact %}
            <tr>
                <th scope="row">From Contact</th>
                <td>{{ liaison.from_contact }}</td>
            </tr>
        {% endif %}
        <tr>
            <th scope="row">To Group{{ liaison.to_groups.all|pluralize }}</th>
            <td>{{ liaison.to_groups_display }}</td>
        </tr>
        {% if liaison.to_contacts %}
            <tr>
                <th scope="row">To Contacts</th>
                <td>{{ liaison.to_contacts|linkify|make_one_per_line|safe|linebreaksbr }}</td>
            </tr>
        {% endif %}
        {% if liaison.cc_contacts %}
            <tr>
                <th scope="row">Cc</th>
                <td>{{ liaison.cc_contacts|linkify|make_one_per_line|safe|linebreaksbr }}</td>
            </tr>
        {% endif %}
        {% if liaison.response_contacts %}
            <tr>
                <th scope="row">Response Contact</th>
                <td>{{ liaison.response_contacts|linkify|make_one_per_line|safe|linebreaksbr }}</td>
            </tr>
        {% endif %}
        {% if liaison.technical_contacts %}
            <tr>
                <th scope="row">Technical Contact</th>
                <td>{{ liaison.technical_contacts|linkify|make_one_per_line|safe|linebreaksbr }}</td>
            </tr>
        {% endif %}
        {% if liaison.action_holder_contacts %}
            <tr>
                <th scope="row">Action Holder Contacts</th>
                <td>{{ liaison.action_holder_contacts|linkify|make_one_per_line|safe|linebreaksbr }}</td>
            </tr>
        {% endif %}
        <tr>
            <th scope="row">Purpose</th>
            <td>{{ liaison.purpose.name }}</td>
        </tr>
        {% if liaison.deadline %}
            <tr>
                <th scope="row">Deadline</th>
                <td>
                    {{ liaison.deadline }}
                    {% if liaison.action_taken %}
                        <span class="actionTaken">Action Taken</span>
                    {% else %}
                        <span class="noActionTaken">Action Needed</span>
                    {% endif %}
                    {% if can_take_care %}
                        <form method="post" class="float-end">
                            {% csrf_token %}
                            <button class="btn btn-warning btn-sm"
                                   type="submit"
                                   value="Mark as action taken"
                                   name="do_action_taken">
                                Mark as action taken
                            </button>
                        </form>
                    {% endif %}
                </td>
            </tr>
        {% endif %}
        {% if relations %}
            <tr>
                <th scope="row">
                    Liaisons referring to this
                </th>
                <td>
                    {% for rel in relations %}
                        <a href="{% url "ietf.liaisons.views.liaison_detail" rel.pk %}">
                            {% if rel.title %}
                                {{ rel.title }}
                            {% else %}
                                Liaison #{{ rel.pk }}
                            {% endif %}
                        </a>
                        <br>
                    {% endfor %}
                </td>
            </tr>
        {% endif %}
        {% if liaison.related_to %}
            {% if liaison.related_to.approved or is_approving %}
                <tr>
                    <th scope="row">
                        Referenced liaison
                    </th>
                    <td>
                        <a href="{% url "ietf.liaisons.views.liaison_detail" liaison.related_to.pk %}">
                            {% if liaison.related_to.title %}
                                {{ liaison.related_to.title }}
                            {% else %}
                                Liaison #{{ liaison.related_to.pk }}
                            {% endif %}
                        </a>
                    </td>
                </tr>
            {% endif %}
        {% endif %}
        {% if liaison.other_identifiers %}
            <tr>
                <th scope="row">
                    Other Identifiers
                </th>
                <td>
                    {{ liaison.other_identifiers }}
                </td>
            </tr>
        {% endif %}
        <tr>
            <th scope="row">
                Attachments
            </th>
            <td>
                {% for doc in liaison.active_attachments.all %}
                    <a href="{{ doc.get_href }}">
                        {{ doc.title }}
                    </a>
                    {% if not forloop.last %}<br>{% endif %}
                {% empty %}
                    (None)
                {% endfor %}
            </td>
        </tr>
        {% if relations_by %}
            <tr>
                <th scope="row">
                    Liaisons referred by this one
                </th>
                <td>
                    {% for rel in relations_by %}
                        <a href="{% url "ietf.liaisons.views.liaison_detail" rel.pk %}">
                            {% if rel.title %}
                                {{ rel.title }}
                            {% else %}
                                Liaison #{{ rel.pk }}
                            {% endif %}
                        </a>
                        <br>
                    {% endfor %}
                </td>
            </tr>
        {% endif %}
        {% if relations_to %}
            <tr>
                <th scope="row">
                    Liaisons referring to this one
                </th>
                <td>
                    {% for rel in relations_to %}
                        <a href="{% url "ietf.liaisons.views.liaison_detail" rel.pk %}">
                            {% if rel.title %}
                                {{ rel.title }}
                            {% else %}
                                Liaison #{{ rel.pk }}
                            {% endif %}
                        </a>
                        <br>
                    {% endfor %}
                </td>
            </tr>
        {% endif %}
        {% if liaison.from_contact and liaison.body %}
            <tr>
                <th scope="row">
                    Body
                </th>
                <td>
                    <pre>{{ liaison.body|maybewordwrap:"80"|urlize_ietf_docs|linkify }}</pre>
                </td>
            </tr>
        {% endif %}
    </tbody>
    </table>
    {% if liaison.state.slug == 'pending' and can_edit or liaison.state.slug == 'dead' and can_edit %}
    <form method="post">
        {% csrf_token %}
    {% endif %}
        {% if liaison.state.slug == 'pending' and can_edit %}
            <a class="btn btn-primary"
               href="{% url "ietf.liaisons.views.liaison_edit" object_id=liaison.pk %}">
                Edit liaison
            </a>
        {% elif liaison.state.slug == 'posted' and  user|has_role:"Secretariat" %}
            <a class="btn btn-primary"
               href="{% url "ietf.liaisons.views.liaison_edit" object_id=liaison.pk %}">
                Edit liaison
            </a>
        {% endif %}
        {% if liaison.state.slug != 'dead' and can_reply %}
            <a class="btn btn-primary"
               href="{% url "ietf.liaisons.views.liaison_reply" object_id=liaison.pk %}">
                Reply to liaison
            </a>
        {% endif %}
        {% if liaison.state.slug == 'pending' and can_edit %}
            <button class="btn btn-primary" type="submit" value="Approve" name="approved">Approve</button>
            <button class="btn btn-primary"
                   type="submit"
                   value="Mark as Dead"
                   name="dead">Mark as dead</button>
        {% endif %}
        {% if liaison.state.slug == 'posted' and  user|has_role:"Secretariat" %}
            <a class="btn btn-primary"
               href="{% url "ietf.liaisons.views.liaison_resend" object_id=liaison.pk %}">
                Resend statement
            </a>
        {% endif %}
        {% if liaison.state.slug == 'dead' and can_edit %}
            <button class="btn btn-primary"
                   type="submit"
                   value="Resurrect"
                   name="resurrect">Resurrect</button>
        {% endif %}
    {% if liaison.state.slug == 'pending' and can_edit or liaison.state.slug == 'dead' and can_edit %}</form>{% endif %}
{% endblock %}